<?php
//======================================================================================
//
// Function: Get HUB_IMPORT dasta
//
// Programmer: JKJ
// Date : 2024-04-22
//
// Copyright Reeft A/S (c) - 2024
//======================================================================================
//======================================================================================
// General config
//======================================================================================
include "config/config.php";
//======================================================================================
// Get input
//======================================================================================
//======================================================================================
// Get session variables
//======================================================================================
include "include/getsession.php";
//======================================================================================
// Set language
//======================================================================================
include "include/set_language.php";
//======================================================================================
// Connect to SQLite database in file
//======================================================================================
$entries_found = 0;
$returnCode = '99';
$returnMsg = 'No data found';
$currentDate = date('Y-m-d');
$currentTime = date('H:i:s');
//======================================================================================
// Set header
//======================================================================================
header('Content-Type: application/json;charset=utf-8');
//======================================================================================
// Connect to some DB
//======================================================================================
//include "include/db_connect.php";
//======================================================================================
// Create SQL
//======================================================================================
$sql = "SELECT * FROM visual_department";
//======================================================================================
// Get data
//======================================================================================
//include "include/db_run_sql.php";
//======================================================================================
// Get time stamp
//======================================================================================
$timeStamp = '';
if ( $timeStamp == '' ) {
$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
$timeStamp = $now->format("Y-m-d H:i:s");
}
$data = array(
"timestamp" => $timeStamp,
"deviceID" => 'deviceID',
"token" => 'token',
"di0_status" => 'd00'
);
//======================================================================================
// Make call to API somewhere
//======================================================================================
$jsonData = json_encode($data);
//header('Content-Type: application/json');
header('Content-Type: application/json;charset=utf-8');
$json_pretty = json_encode(json_decode($jsonData), JSON_PRETTY_PRINT);
// echo $json_pretty;
// echo "<br>";
// echo $url;
//$url = 'http://10.30.1.43:81/cgi-bin/hub_config';
$url = 'http://10.30.1.43:81/cgi-bin/hub_import';
// Create a new cURL resource
$ch = curl_init($url);
// Attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt($ch, CURLOPT_HEADER, false); // we do not need headers
// curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
// Execute the POST request
$result = curl_exec($ch);
$ary = curl_getinfo($ch);
// Close cURL resource
curl_close($ch);
print_r($result);
?>